package com.china08.yxyapi.api.manage.tec.teaching.zujuan.previewpaper;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.security.profile.YxyProfile;
import com.china08.yxyapi.service.manage.tec.teaching.zujuan.ZujuanQuestionService;

import io.swagger.annotations.ApiOperation;

/**
 * 保存试卷
 * 
 * 
 */
@RestController
@CrossOrigin
public class ZujuanPaperSaveController extends YxyApiBaseController {

    @Autowired
    private ZujuanQuestionService zujuanQuestionService;

    @ApiOperation(value = "保存试卷")
    @RequestMapping(value = "/api_yw/manage/tec/teaching/zujuan/paper/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {

        // 分卷及注释
        List<PaperAnnotation> paperAnnotationlist = new ArrayList<ZujuanPaperSaveController.PaperAnnotation>();
        PaperAnnotation paperAnnotation = null;
        if (StringUtils.isNoneBlank(reqModel.title5)) {
            paperAnnotation = new PaperAnnotation();
            paperAnnotation.num = 1;
            paperAnnotation.paperAnnotation = reqModel.title5;
            paperAnnotationlist.add(paperAnnotation);
        }
        if (StringUtils.isNoneBlank(reqModel.title6)) {
            paperAnnotation = new PaperAnnotation();
            paperAnnotation.num = 2;
            paperAnnotation.paperAnnotation = reqModel.title6;
            paperAnnotationlist.add(paperAnnotation);
        }

        // 大题及注释
        List<QuestionAnnotation> questionAnnotationlist = new ArrayList<ZujuanPaperSaveController.QuestionAnnotation>();
        QuestionAnnotation questionAnnotation = null;
        if (StringUtils.isNoneBlank(reqModel.title7)) {
            questionAnnotation = new QuestionAnnotation();
            questionAnnotation.num = 1;
            questionAnnotation.questionAnnotation = reqModel.title7;
            questionAnnotationlist.add(questionAnnotation);
        }
        if (StringUtils.isNoneBlank(reqModel.title8)) {
            questionAnnotation = new QuestionAnnotation();
            questionAnnotation.num = 2;
            questionAnnotation.questionAnnotation = reqModel.title8;
            questionAnnotationlist.add(questionAnnotation);
        }

        if (StringUtils.isNoneBlank(reqModel.title9)) {
            questionAnnotation = new QuestionAnnotation();
            questionAnnotation.num = 3;
            questionAnnotation.questionAnnotation = reqModel.title9;
            questionAnnotationlist.add(questionAnnotation);
        }

        if (StringUtils.isNoneBlank(reqModel.title10)) {
            questionAnnotation = new QuestionAnnotation();
            questionAnnotation.num = 4;
            questionAnnotation.questionAnnotation = reqModel.title10;
            questionAnnotationlist.add(questionAnnotation);
        }

        reqModel.setPaperAnnotationlist(paperAnnotationlist);
        reqModel.setQuestionAnnotationlist(questionAnnotationlist);

        YxyProfile profile = getProfile(request, response);
        zujuanQuestionService.SavePaper(reqModel, profile);
        RespModel respModel = new RespModel();
        respModel.setMessage("保存试卷成功");
        return respModel;
    }

    public static class ReqModel extends YxyApiReqModel {
        // 试卷id
        public String paperId;
        // 学段id
        public String stage;
        // 学段名称
        public String stageName;
        // 学科id
        public String subject;
        // 学科名称
        public String subjectName;
        // 试题请求模型
        public List<QuestionModel> quesIdList;
        // 试卷的基本配置
        public List<String> checkList;
        // 主标题
        public String title1;
        // 副标题
        public String title2;
        // 试卷信息栏
        public String title3;
        // 考生输入栏
        public String title4;
        // 第1卷说明
        public String title5;
        // 第2卷说明
        public String title6;
        // 单选题注释及分数
        public String title7;
        // 多选题注释及分数
        public String title8;
        // 填空题注释及分数
        public String title9;
        // 解答题注释及分数
        public String title10;
        // 分卷注释
        public List<PaperAnnotation> paperAnnotationlist;
        // 大题注释
        public List<QuestionAnnotation> questionAnnotationlist;

        public List<PaperAnnotation> getPaperAnnotationlist() {
            return paperAnnotationlist;
        }

        public void setPaperAnnotationlist(List<PaperAnnotation> paperAnnotationlist) {
            this.paperAnnotationlist = paperAnnotationlist;
        }

        public List<QuestionAnnotation> getQuestionAnnotationlist() {
            return questionAnnotationlist;
        }

        public void setQuestionAnnotationlist(List<QuestionAnnotation> questionAnnotationlist) {
            this.questionAnnotationlist = questionAnnotationlist;
        }

        @Override
        public void autoCheck() {
            super.autoCheck();
        }
    }

    /**
     * 题的响应
     */
    public static class QuestionModel {
        // 试题id
        public String quesId;
        // 试题涉及的知识点
        public List<Integer> know;
        // 试题的分数
        public Integer point;
        // 题型
        public String quesType;
    }

    /**
     * 分卷及注释
     */
    public static class PaperAnnotation {
        // 1卷 2 卷
        public Integer num;
        public String paperAnnotation;

        public Integer getNum() {
            return num;
        }

        public void setNum(Integer num) {
            this.num = num;
        }

        public String getPaperAnnotation() {
            return paperAnnotation;
        }

        public void setPaperAnnotation(String paperAnnotation) {
            this.paperAnnotation = paperAnnotation;
        }

    }

    /**
     * 大题及注释
     */
    public static class QuestionAnnotation {
        // 1大题 2大题 3大题 4大题
        public Integer num;
        public String questionAnnotation;

        public Integer getNum() {
            return num;
        }

        public void setNum(Integer num) {
            this.num = num;
        }

        public String getQuestionAnnotation() {
            return questionAnnotation;
        }

        public void setQuestionAnnotation(String questionAnnotation) {
            this.questionAnnotation = questionAnnotation;
        }

    }

    protected static class RespModel extends YxyApiRespModel {

    }

}
